<?php
/*
Engineers: Alex Arey, Derek Shue, Sean Margison
Updated: 12/10/2011
Module Description: The admin controller is responsible for directing the flow of data for the admin.
The Admin controller facilitates adding, editting and deleting users and manages term data.
The admin can add term sessions and open them for submission from students, faculty or community partners.
*/


class AdminController extends Zend_Controller_Action
{

    public function init()
    {
		//get user session
       	$auth = Zend_Auth::getInstance();
		
		//check if user is logged in, otherwise redirect to home page
		if($auth->hasIdentity()){
			$userID = $auth->getIdentity()->getUID();
		}else{
			$this->_helper->redirector('index','index');
			return;
		}
		$this->checkAdmin();
		
		
    }

	private function checkSuperAdmin(){
		$auth = Zend_Auth::getInstance();
		if($auth->hasIdentity()){
			$userRank = $auth->getIdentity()->getUserRank();
			if($userRank<3){
						$this->_helper->redirector('index','index');
						return;
			}
		}else{
			$this->_helper->redirector('index','index');
			return;
		}
	
	}
	
	private function checkAdmin(){
		$auth = Zend_Auth::getInstance();
		if($auth->hasIdentity()){
			$userRank = $auth->getIdentity()->getUserRank();
			if($userRank<2){
						$this->_helper->redirector('index','index');
						return;
			}
		}else{
			$this->_helper->redirector('index','index');
			return;
		}
	
	}
	
	
	
    public function indexAction()
    {
		//admin index page shows users' information
        $users = new Application_Model_DbTable_Users();
        $this->view->entries = $users->fetchAll();
	
    }
	
		public function deletecourseAction() {
		if ($this -> getRequest() -> isPost()) {
			$del = $this -> getRequest() -> getPost('del');
			if ($del == 'Yes') {
				$cid = $this -> _getParam('CID');
				$courses = new Application_Model_DbTable_Courses();
				$courses->deleteCourse('CID = '.$cid);
			}

			$this -> _helper -> redirector('mycourses');
		} else {
			$cid = $this -> _getParam('CID');
			$courses = new Application_Model_DbTable_Courses();
			$this -> view -> course = $courses -> getCourse('CID = ' . $cid);
		}
	}
	
	public function submitcourseAction(){

		
		$form = new Application_Form_AddCourseToFaculty();
        $form->submit->setLabel('Add Course');
        $term = new Application_Model_Term();

		
		
		$courses = new Application_Model_DbTable_Courses();
		$currTerm = $term->getCurrentOpenTermStr('facCourse');
		if(!$currTerm){
			$this->view->noTerm = true;
			return;
		}
		$this->view->term = $currTerm;
		$this->view->form = $form;

		 if ($this->getRequest()->isPost()) {
		 	$formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
				
				$teacherID = $form->getValue('TEACHERID');
				
            	$coursenumber = $form->getValue('COURSENUMBER');
				$department = $form->getValue('DEPARTMENT');
				$description = $form->getValue('DESCRIPTION');
				$coursename = $form->getValue('COURSENAME');	
				$check_syllabus = $form->getValue('SYLLABUS');
				if(substr($check_syllabus,0,7)=="http://"){//add http:// if not already present; needed to display link correctly
					$syllabus = $form->getValue('SYLLABUS');
				}else{
					$syllabus = "http://".$check_syllabus;
				}

					try{
						$courses->addCourse($coursenumber,$coursename,$description, $department, $teacherID, $currTerm, $syllabus);
					}
					catch(Exception $e){
						echo $e->getMessage();
						return null;
					}
				$this->_helper->redirector('index','index');
			}
		 }
	}

	/**
	* Action controller handles user creation
	*/
    public function submitAction()
    {
		$this->checkSuperAdmin();
        $form = new Application_Form_AddUser();
        $form->submit->setLabel('Add');
        $this->view->form = $form;
        
		
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
			
                $loginname = $form->getValue('LOGINNAME');
                $pw = md5($form->getValue('PW'));
			    $rank = $form->getValue('RANK');
				$type = $form->getValue('TYPE');
				
				try{
                $users = new Application_Model_DbTable_Users();
				$this->view->existsError = false;
					try{
						$users->getUser('LOGINNAME = \''.$loginname.'\'');
						$this->view->existsError = true;
					}catch(Exception $e){ //login does not exist; getUser should have thrown exception.
						$userId = $users->addUser($loginname, $pw, $rank, $type);
						
						//if an admin is being submitted, submit basic profile data
						if($rank>0){
							if($type == "student"){
							$profile = new Application_Model_DbTable_Students();
							$profile->addStudent($userId,"","","","","","","","","");
							}
							elseif($type == "teacher"){
							$profile = new Application_Model_DbTable_Teachers();
							$profile->addTeacher($userId,"","","","");
							}
							elseif($type == "organization"){
							$profile = new Application_Model_DbTable_Organizations();
							$profile->addOrganization($userId, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
							}
						}
						$this->_helper->redirector('index');
					}
				}
				catch(Exception $e){
					$this->_helper->redirector('index');
				}	
				
            } else {
                $form->populate($formData);
            }
        }
            
    }
	
public function addtagAction(){
	$form = new Application_Form_AddTag();
	$this->view->form = $form;
	$tagnames = new Application_Model_DbTable_Tagnames();
	$requests = new Application_Model_DbTable_VolunteerRequests();
	$internpositions = new Application_Model_DbTable_InternPositions();
	$volunteersmodel = new Application_Model_DbTable_VolunteerRequests();
	$internsmodel = new Application_Model_DbTable_InternPositions();
	
	if ($this->getRequest()->isPost()) {
        $formData = $this->getRequest()->getPost();
		if ($form->isValid($formData)) {
			$tagname = $form->getValue('TAGNAME');
			$tagnames->addTagname($tagname);			
		}
	
		else{
			$form->populate($formData);
		}
		
	}
	$this->view->currenttags = $tagnames->getAllTagnames();
	
}
	
	/**
	* Action controller handles user edits
	*/
	public function editAction()
    {
		$auth=Zend_Auth::getInstance();
		$this->checkSuperAdmin();
		if($auth->hasIdentity()){
			$userRank = $auth->getIdentity()->getUserRank();
			if($userRank<3){
						$this->_helper->redirector('index','index');
						return;
			}
		}else{
			$this->_helper->redirector('index','index');
			return;
		}
		
        $form = new Application_Form_AddUser();
     	$form->submit->setLabel('Save');
        $this->view->form = $form;
        
		
		
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = (int)$form->getValue('ID');
                $loginname = $form->getValue('LOGINNAME');
				
				if($form->getValue('PW')){
					$pw = md5($form->getValue('PW'));
				}
				else{
					$pw = "";
					}
				$rank = $form->getValue('RANK');
				$type = $form->getValue('TYPE');
				$users = new Application_Model_DbTable_Users();
				
				if($rank>0){
					if($type == "student"){
					$profile = new Application_Model_DbTable_Students();
					$profile->addStudent($id,"","","","","","","","","");
					}
					elseif($type == "teacher"){
					$profile = new Application_Model_DbTable_Teachers();
					$profile->addTeacher($id,"","","","");
					}
					elseif($type == "organization"){
					$profile = new Application_Model_DbTable_Organizations();
					$profile->addOrganization($id, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
					}
				}
				
				
                $users->updateUser($id, $loginname, $pw, $rank, $type);
                $this->_helper->redirector('index');
            } else {
                $form->populate($formData);
            }
        } else {
            $id = $this->_getParam('ID');
            if ($id > 0) {
                $users = new Application_Model_DbTable_Users();
                $form->populate($users->getUser("ID = ".$id));
				
				if($form->PW->getValue()==""){
						$form->PW->setAttrib('disabled', 'disabled');
						$form->PW2->setAttrib('disabled', 'disabled');
				}
				$form->PW->setValue("");	
				
				$currentType = $form->TYPE->getValue();
				if($currentType != "student"){
					
					$form->TYPE->setAttrib('disabled', 'disabled');
					$form->TYPE->setLabel(  "User Type: *Delete the user and re-enter if type must be altered*");
				}
		
            }
        }
        
    }
    
	/**
	* Action controller handles user deletes
	*/
    public function deleteAction()
    {
		$this->checkSuperAdmin();
        if ($this->getRequest()->isPost()) {
            $del = $this->getRequest()->getPost('del');
            if ($del == 'Yes') {
                $id = $this->getRequest()->getPost('ID');
                $users = new Application_Model_DbTable_Users();
				$users->deleteUser($id);
            }
           $this->_helper->redirector('index');
		} 
		else {
            $id = $this->_getParam('ID');
            $users = new Application_Model_DbTable_Users();
            $this->view->user = $users->getUser("ID = ".$id);
        }
    }
	
	/**
	* Action controller handles creation of new terms
	*/
	public function submittermAction()
    {
        $form = new Application_Form_Terms();
        $form->submit->setLabel('Add');
        $this->view->form = $form;
        	
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
			
                $term = $form->getValue('TERM');
                $year = $form->getValue('YEAR');
                $termsModel = new Application_Model_Term();
			    $studentappbegin = $termsModel->parseDateToOracle($form->getValue('STUDENTAPPSTART'));
				$studentappend = $termsModel->parseDateToOracle($form->getValue('STUDENTAPPEND'));
				$facultycoursebegin = $termsModel->parseDateToOracle($form->getValue('FACULTYCOURSESTART'));
				$facultycourseend = $termsModel->parseDateToOracle($form->getValue('FACULTYCOURSEEND'));
				$partnerinternbegin = $termsModel->parseDateToOracle($form->getValue('PARTNERINTERNSTART'));
				$partnerinternend = $termsModel->parseDateToOracle($form->getValue('PARTNERINTERNEND'));
				$partnervolunteerbegin = $termsModel->parseDateToOracle($form->getValue('PARTNERVOLUNTEERSTART'));
				$partnervolunteerend = $termsModel->parseDateToOracle($form->getValue('PARTNERVOLUNTEEREND'));
				$ADMINISTRATIVEbegin = $termsModel->parseDateToOracle($form->getValue('ADMINISTRATIVESTART'));
				$ADMINISTRATIVEend = $termsModel->parseDateToOracle($form->getValue('ADMINISTRATIVEEND'));
	
				
				try{
					$terms = new Application_Model_DbTable_Terms();
					$terms->addTerm(strtoupper($term), $year, $studentappbegin, $studentappend, $facultycoursebegin , $facultycourseend,
						$partnerinternbegin, $partnerinternend, $partnervolunteerbegin, $partnervolunteerend, $ADMINISTRATIVEbegin, $ADMINISTRATIVEend );
					$this->_helper->redirector('manageterms','admin');
				}
				catch(Exception $e){
					echo $e->getMessage();
					$form->populate($formData);
					return null;
				}
            } 
			else{
                $form->populate($formData);
				$form->STUDENTAPPSTART->setValue($termsModel->parseDateFromOracle($form->STUDENTAPPSTART->getValue()));
				$form->STUDENTAPPEND->setValue($termsModel->parseDateFromOracle($form->STUDENTAPPEND->getValue()));
				$form->FACULTYCOURSESTART->setValue($termsModel->parseDateFromOracle($form->FACULTYCOURSESTART->getValue()));
				$form->FACULTYCOURSEEND->setValue($termsModel->parseDateFromOracle($form->FACULTYCOURSEEND->getValue()));
				$form->PARTNERINTERNSTART->setValue($termsModel->parseDateFromOracle($form->PARTNERINTERNSTART->getValue()));
				$form->PARTNERINTERNEND->setValue($termsModel->parseDateFromOracle($form->PARTNERINTERNEND->getValue()));
				$form->PARTNERVOLUNTEERSTART->setValue($termsModel->parseDateFromOracle($form->PARTNERVOLUNTEERSTART->getValue()));
				$form->PARTNERVOLUNTEEREND->setValue($termsModel->parseDateFromOracle($form->PARTNERVOLUNTEEREND->getValue()));
				$form->ADMINISTRATIVESTART->setValue($termsModel->parseDateFromOracle($form->ADMINISTRATIVESTART->getValue()));
				$form->ADMINISTRATIVEEND->setValue($termsModel->parseDateFromOracle($form->ADMINISTRATIVEEND->getValue()));
            }
        }
            
    }
	
	/**
	* Action controller handles term edits
	*/
	public function edittermAction()
    {
        $form = new Application_Form_Terms();
		$form->submit->setLabel('Save');
        $this->view->form = $form;
		$termsModel = new Application_Model_Term();
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
              $term = $form->getValue('TERM');
                $year = $form->getValue('YEAR');
                
			    $studentappbegin =  $termsModel->parseDateToOracle($form->getValue('STUDENTAPPSTART'));
				$studentappend =  $termsModel->parseDateToOracle($form->getValue('STUDENTAPPEND'));
				$facultycoursebegin =  $termsModel->parseDateToOracle($form->getValue('FACULTYCOURSESTART'));
				$facultycourseend =  $termsModel->parseDateToOracle($form->getValue('FACULTYCOURSEEND'));
				$partnerinternbegin = $termsModel->parseDateToOracle($form->getValue('PARTNERINTERNSTART'));
				$partnerinternend = $termsModel->parseDateToOracle($form->getValue('PARTNERINTERNEND'));
				$partnervolunteerbegin = $termsModel->parseDateToOracle($form->getValue('PARTNERVOLUNTEERSTART'));
				$partnervolunteerend = $termsModel->parseDateToOracle($form->getValue('PARTNERVOLUNTEEREND'));
				$ADMINISTRATIVEbegin = $termsModel->parseDateToOracle($form->getValue('ADMINISTRATIVESTART'));
				$ADMINISTRATIVEend = $termsModel->parseDateToOracle($form->getValue('ADMINISTRATIVEEND'));
				try{
					$terms = new Application_Model_DbTable_Terms();
					$terms->updateTerm(strtoupper($term), $year, $studentappbegin, $studentappend, $facultycoursebegin , $facultycourseend,
						$partnerinternbegin, $partnerinternend, $partnervolunteerbegin, $partnervolunteerend, $ADMINISTRATIVEbegin, $ADMINISTRATIVEend );
					$this->_helper->redirector('manageterms','ADMINISTRATIVE');
				}
				catch(Exception $e){
					echo $e->getMessage();
					return null;
				}
            } 
			else{
                $form->populate($formData);
            }
        }
		else {
            $termname = $this->_getParam('term');
			$year = $this->_getParam('year');
            if($termname&&$year){
                $terms = new Application_Model_DbTable_Terms();
                $form->populate($terms->getTerm("TERM = '". strtoupper($termname) . "' AND YEAR = " . $year));

				$form->STUDENTAPPSTART->setValue($termsModel->parseDateFromOracle($form->STUDENTAPPSTART->getValue()));
				$form->STUDENTAPPEND->setValue($termsModel->parseDateFromOracle($form->STUDENTAPPEND->getValue()));
				$form->FACULTYCOURSESTART->setValue($termsModel->parseDateFromOracle($form->FACULTYCOURSESTART->getValue()));
				$form->FACULTYCOURSEEND->setValue($termsModel->parseDateFromOracle($form->FACULTYCOURSEEND->getValue()));
				$form->PARTNERINTERNSTART->setValue($termsModel->parseDateFromOracle($form->PARTNERINTERNSTART->getValue()));
				$form->PARTNERINTERNEND->setValue($termsModel->parseDateFromOracle($form->PARTNERINTERNEND->getValue()));
				$form->PARTNERVOLUNTEERSTART->setValue($termsModel->parseDateFromOracle($form->PARTNERVOLUNTEERSTART->getValue()));
				$form->PARTNERVOLUNTEEREND->setValue($termsModel->parseDateFromOracle($form->PARTNERVOLUNTEEREND->getValue()));
				$form->ADMINISTRATIVESTART->setValue($termsModel->parseDateFromOracle($form->ADMINISTRATIVESTART->getValue()));
				$form->ADMINISTRATIVEEND->setValue($termsModel->parseDateFromOracle($form->ADMINISTRATIVEEND->getValue()));
            }
        }
        
    }
    
	/**
	* Action controller handles term deletion
	*/
    public function deletetermAction()
    {
        if ($this->getRequest()->isPost()) {
            $del = $this->getRequest()->getPost('del');
            if ($del == 'Yes') {
                $termname = $this->getRequest()->getPost('term');
				$year = $this->getRequest()->getPost('year');
                $terms = new Application_Model_DbTable_Terms();
				$terms->deleteTerm("TERM = '".$termname ."' AND YEAR = ". $year);
            }
			
				
           $this->_helper->redirector('manageterms','admin');
        } else {
            $termname = $this->_getParam('term');
			$year = $this->_getParam('year');
            $terms = new Application_Model_DbTable_Terms();
            $this->view->term = $terms->getTerm("TERM = '".$termname ."' AND YEAR = ". $year);
        }
    }
    
    
    /**
	* Action controller handles the display of all current internship application
	*/
    public function internappAction()
    {
    	$applicationQuery = new Application_Model_InternshipQuery();
		$results = $applicationQuery->selectCurrentApplications_AD();
		$apps = array();
		foreach($results as $res){
			$internapp = new Application_Model_InternshipApp();
			$internapp->init($res['APPID']);
			$apps[] = $internapp;
		}
		$this->view->applications = $apps;
    }
    
    /**
	* Action controller handles the display of all current intern requests
	*/
    public function internreqAction()
    {
    	$positionQuery = new Application_Model_InternshipQuery();
		$positions = $positionQuery->getInternships_AD();
		foreach($positions as $pos)
		{
			$posid = $pos['POSID'];
			$name = $positionQuery->getPartnerNameForPID($posid);
			$pos['PARTNERNAME'] = $name;
		}
		$this->view->positions = $positions;
    }
    
    /**
	* Action controller handles term management
	*/
    public function managetermsAction()
    {
		$auth = Zend_Auth::getInstance(); 
		if($auth->hasIdentity()){
			$userId = $auth->getIdentity()->getUID();
		}else{
			$this->_helper->redirector('index','index');
			return;
		}

		$terms  = new Application_Model_Term;
		
		try{
		
		$rows = $terms->getAllTerms();
			
		}
		catch(Exception $e){
			echo $e.getMessage();
			return null;		
		}
		
		$this->view->terms = $rows;
    }
    
    /**
	* Action controller handles the viewing of details for an internship request
	*/
    public function viewinternreqAction()
    {
		//get position data
		$positionQuery = new Application_Model_InternshipQuery();
		try{
			$posid = $this->getRequest()->getParam('position');
			$row = $positionQuery->selectInternship_ID($posid);
			$this->view->position = $row;
			$partnerName = $positionQuery->getPartnerNameForPID($posid);
			$this->view->partner = $partnerName;
			$form = new Application_Form_InternRequestAdmin();
			$this->view->form = $form;
		}catch(Exception $e){
			$this->view->position = null;
		}
		if($this->getRequest()->isPost()){
			$nosubmit = false;
		    $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $accepted = $form->getValue('ACCEPT');
                $positionsGrantedInput = $form->getValue('GRANT');
                if($accepted == 'y'){
                	$positionsGranted= $positionsGrantedInput;
                }
                else if($accepted == 'n'){
                	$positionsGranted = 0;
                }else{
                	$nosubmit = true;
                }
				if(!$nosubmit){
					$requestdbt = new Application_Model_DbTable_InternPositions();
                	$requestdbt->acceptInternRequest($row['POSID'], $accepted, $positionsGranted);
                	$this->_helper->redirector('internreq','admin');
                }else{
                	$this->view->notsubmitted = true;
                }
            }
		}
    }

	/**
	* Action controller handles managing volunteer requests; connecting them to courses.
	*/
		public function managevolunteersAction(){
	
		$auth = Zend_Auth::getInstance(); 
		if($auth->hasIdentity()){
			$partnerID = $auth->getIdentity()->getUID();
		}else{
			$this->_helper->redirector('index','index');
			return;
		}

		$form = new Application_Form_Search();
		$this->view->form = $form;
		$positionQuery = new Application_Model_VolunteerQuery();
		$associationQuery = new Application_Model_CourseAssociationQuery();
		$termModel = new Application_Model_Term();
		
		//set defaults
		$termModifier = 'ns';
		$term = $termModel->getCurrentOpenTerm('admnVol');
		$name = '';
		
		//overwrite defaults with form data
		if ($this->getRequest()->isPost()) {
		        $formData = $this->getRequest()->getPost();
		        if ($form->isValid($formData)) {		
					$term = array('term'=>$form->getValue('TERM') , 'year' => $form->getValue('YEAR'));
		            $termModifier = $form->getValue('MODIFIER');
					$name = $form->getValue('NAME');								 
		        }
		}
		try{
			$positions = $positionQuery->selectVRs_Admin($term, $termModifier, $name);
			$associates = $associationQuery->selectCAs_Admin($term, $termModifier, $name);
		}
		catch(Exception $e){
			echo $e.getMessage();
			return null;
		}
		
		$this->view->positions = $positions;
		$this->view->associates = $associates;
		}
	
	/**
	* Action controller handles adding associations between volunteer requests and courses.
	*/
    public function addcourseassociationAction(){
		$auth = Zend_Auth::getInstance(); 
		if($auth->hasIdentity()){
			$id = $auth->getIdentity()->getUID();
		}else{
			$this->_helper->redirector('index','index');
			return;
		}
		$coursequery = new Application_Model_CoursesQuery();
		$volunteerquery = new Application_Model_VolunteerQuery();
		
// 		$courses = $coursequery->getCourses_Admin();
// 		$volunteerrequests = $volunteerquery->getVRs_Admin();
		
		if($this->getRequest()->getParam('term')){
			$courses = $coursequery->getCoursesForTerm_Admin('\''.$this->getRequest()->getParam('term').'\'');
			$volunteerrequests = $volunteerquery->getVRsByTerm_Admin($this->getRequest()->getParam('term'));
			$this->view->term = $this->getRequest()->getParam('term');
		}
		else{
			$courses = $coursequery->getCourses_Admin();
			$volunteerrequests = $volunteerquery->getVRs_Admin();
			$this->view->term = "All Terms";
		}
		$form = new Application_Form_CourseAssociation(array('courses'=>$courses, 'VRs'=>$volunteerrequests));
		

		//$form = new Application_Form_CourseAssociation();
		$this->view->form = $form;
		$courseassociations = new Application_Model_DbTable_CourseAssociations();
		if ($this->getRequest()->isPost()) {
		        $formData = $this->getRequest()->getPost();
		        if ($form->isValid($formData)) {		
				
					$rid = $form->getValue('RID');
					$cid = $form->getValue('CID');
					$numpositions = $form->getValue('NUMPOSITIONS');
					
					
					$courses = new Application_Model_DbTable_Courses();
					$vrs = new Application_Model_DbTable_VolunteerRequests();
					
					try{
					$course = $courses->getCourse("CID = " . $cid);
					$vr = $vrs->getVolunteerRequest("VRID = " . $rid);
					}
					catch(Exception $e){
						echo $e->getMessage();
						return null;
					}
					
					if($course['TERM'] == $vr['TERM']){
					$term = $course['TERM'];
						try{
							if(!$courseassociations->existsCourseAssociation($rid,$cid)){
								$courseassociations->addCourseAssociation($rid,$cid,$numpositions,$term);
							}else{
								$courseassociations->updateCourseAssociation($rid,$cid,$numpositions,$term);
							}
							$this->_helper->redirector('managevolunteers','admin');
							return;
						}
						catch(Exception $e){
							echo $e->getMessage();
							return null;
						}
					}
				}
			}
			$t = new Application_Model_Term();
			$this->view->otherTerms = $t->getAllTermsStr();
		}
		
		public function allapplicationsAction(){
			$applicationQuery = new Application_Model_InternshipQuery();
			$results = $applicationQuery->selectApplications_AD();
			$apps = array();
			foreach($results as $res){
				$internapp = new Application_Model_InternshipApp();
				$internapp->init($res['APPID']);
				$apps[] = $internapp;
			}
			$this->view->applications = $apps;
		}
		
		
		public function manageannouncementsAction(){
			$form = new Application_Form_Announcements();
			$announcementsModel = new Application_Model_DbTable_Announcements();
			if ($this->getRequest()->isPost()) {
				$formData = $this->getRequest()->getPost();
				if ($form->isValid($formData)) {
					$announcementsModel->updateAnnouncement('STUDENT', $form->getValue('STUDENT'));
					$announcementsModel->updateAnnouncement('PARTNER', $form->getValue('PARTNER'));
					$announcementsModel->updateAnnouncement('ADMIN', $form->getValue('ADMIN'));
					$announcementsModel->updateAnnouncement('FACULTY', $form->getValue('FACULTY'));
					$announcementsModel->updateAnnouncement('NOLOGIN', $form->getValue('NOLOGIN'));
				}
				$this->_helper->redirector('manageannouncements','admin');
			}
			$form->populate(array(
				'STUDENT'=>$announcementsModel->getAnnouncement('STUDENT'),
				'PARTNER'=>$announcementsModel->getAnnouncement('PARTNER'),
				'ADMIN'=>$announcementsModel->getAnnouncement('ADMIN'),
				'FACULTY'=>$announcementsModel->getAnnouncement('FACULTY'),
				'NOLOGIN'=>$announcementsModel->getAnnouncement('NOLOGIN')
			));
			$this->view->form = $form;
		}
    
    
}
